import { defineConfig, loadEnv } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import AutoImport from 'unplugin-auto-import/vite'
import Unocss from 'unocss/vite'
import path from 'path'

export default defineConfig(({ mode }) => {
  const config = loadEnv('production', './')
  return {
    plugins: [
      uni(),
      Unocss(),
      AutoImport({
        imports: [
          'vue',
          {
            '@dcloudio/uni-app': [
              'onLaunch',
              'onError',
              'onInit',
              'onReady',
              'onResize',
              'onBackPress',
              'onAddToFavorites',
              'onLoad',
              'onUnload',
              'onShow',
              'onHide',
              'onPageScroll',
              'onPullDownRefresh',
              'onReachBottom',
              'onShareAppMessage',
              'onShareTimeline'
            ]
          }
        ],
        eslintrc: {
          enabled: true,
          filepath: './.eslintrc-auto-import.json',
          globalsPropValue: true,
        },
      })
    ],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src')
      }
    },
    esbuild:{
      drop: mode === 'production' ? ["console","debugger"]: [],
    },
    server: {
      port: 3000,
      proxy: {
        '/api': {
          target: config.VITE_BASE_URL, // 目标服务  
          changeOrigin: true,
          rewrite: path => path.replace(/^\/api/, ''),
        }
      }
    },
    transpileDependencies:['@dcloudio/uni-ui'],
  }
})
